Fixed some bugs after merging with master.