refactoring to use Maze object