added 0-index error checking