simplify code and create rotation library