Added database writing functionality.