Database connection pooling + minor refactoring