Fix little bugs and prettify code