refactored code into helpers