refactor database functions using closure
z