Various fixes in database synchronisation and handling of incoming messages