hw6. refactor 4 move and rotate handlers into one function