fix the bugs from refactor