Updated the find_in_periodic_array function to work better.