improved style, fixed some bugs