Additional database layer cleaning and assorted bugfixing