fixed determineIndex logic
fixed determineIndex logic