Fixed some errors and warnings.
Fixed some bugs caused from last commit