improvements on error handling and connection pool