Moving DB sync

Taking database synchronisation out of main script