refactor depth limited search