refactored main method and cleaned up.