Fix errors and reformat