Refactoring bfs and inLevelOrder methods