Added database initialization to factory function