some optimizations
merged