Ruibin's bug fix implemented