refactoring maze generator