Fixed some bugs and warnings.