Added some helper functions
added weighting code in rotation control.