Refactor maze traversal solution