Added index checking