Update the function by Xiaoyu Liu