some re-ordering
fixed a bug with conversion of flat indices to grid, mocked up methods for exit handling