speed up a few SQL queries