Moved rotate to a function