fixed indexing error
added another check