Fix two problems of not returning connections to the pool or returning them at the wrong time