added db functions, moved to lib