Moved code into methods