optimized some sql - not all of them