refactored the program