Fixed db update logic