fix negative and out of array numbers