add some optimizations, but have not done