refactored the main class