Hamels sharp as Phillies beat Pirates