refactored code into methods