do_castle refactor