Corrected duplicate variable declarations, variable name change from 'var_index' to 'rot_index' and corrected minor bugs