re-ordered code into methods