refactoring dungeon code