small query optimization and random clean ups.