Modified code with rotateBoard function