refactors couple of repetitions