refactor maze methods, fix bug in flag field