Fixed bugs and changed db schema