refactored simplified code