Simplified, fixed a connection leak