add more optimization and fixes