some repairs and optimizations