Fixes and inital work on database