Added database hook interface. Improved some memory useage