refactor routines