Added database replication on each database write and purge function for running as a cron job