refactored to push logic into class