Fixed some bugs and semantic errors