implemented bredth first search