refactor some of the shifting code