Clarified calc_rotation return value. Made a proper logic loop.