Removed useless diff division by 3, fixed typo in calc_rotation, changed diff threshold to 50 (empirically tested to be somewhat good).