Format and some minor bug fix