factored out rotate() function