add check for array out of bounds