refactoring with _rotate method

Re-factored the _rotate method to remove usage of goto