Fixed error when computing rowmax, also added reverse calculation to
check if result is valid