refactored main program