added Chih-Yen's code