Updated code from Yue