fine tune and bug fixed