Fixed some bugs, added some functionality to db