Implemented internal operation for database setup. Fixed query-related issues.