refactored and fixed hp problem