many fixes all around, the formatting code being the most invasive change