refactored rotor function