Refactor: move common routines into separate methods