fixed few database bugs