Updated database functional. Fixed few bugs.