some changes to optimize