refactoring maze