Improve all sql queries