fix some bugs on opt
fix a lot of warnings