Code refactor and clean up Pharm