Updated db functions
Some fixes