bugfix + better consistant db saving