added yupeng's implementation.