Fix: synchronized all calls to Database functions.
Mod: removed synchronization from stats exit thread