Reformat all the code and add some doc