misc optimization and clean up