move db update deeper into run fn
more generic functions, adding comments