Refactored code moving code out of the main class