database functions complete, not tested