Map and grid fixed

The row was column and the column was rows.
The algorithm was flawed also