Cleaned up the database interface for postgresql