Improved SQL queries etc.
Simplificiations and restructuring