minor optimizations and debugging