more SQL improvements