first small refactor - removing redundant code, splitting into methods