Refactoring code, splitting it into separate methods