step2: bug fix, almost finished