changed the queue to stack so it's depth first rather than breadth first search.