prettify and fix some bugs