Adding failsafe field to connection and fixing a memory leak