Cache results of the shift. Also add test for checking if implementation can work when result is one of the arguments.