changed the bounds check and my invertRow so that they work and are easier
to read