small optimizations and changes