fixed some bugs and removed warings