phash: fixes and improvements