Changed range checks from < to <=.