fixed some permissions issues; optimized some queries.