Added connection pooling. Some refactoring.