Fixed some bugs after merged with master