fix negative array indices