add some optimizations and bem