db functions tested. code cleaned