some improvements made on tao's feedback