Query optimization

Unnecessary LEFT JOINs turned into JOINs.