working version of BFS in java