A slightly optimized version of the maze solver.