refactored main logic in separate class