Remove SQL from WebUI module, and move it into Database, plus some bug fixing from the previous database consolidation