Bugfix pq test 202

Fixed various race conditions