Reformat and simplify code