refactor to use a register (phase 1)