Added longer test, fixed a possible segfault when queue is empty