Removed unused argument and added check for array length