Fixed some small bugs, and corrected merge errors