optimize some queries