decouple db from functions