Fixed connection expiration calculation.
Fixed some valgrind related issues.