Reformat and fix code