Refactored database to individually open and close a connection for each request