refactored logic into separate class