small optimizations and cleaning