Fixed index out of bonds if statement.