Fix the bugs appeared after last PR