move db update code and add debugs