fixed some bugs and code convention