housecleaning: reformat and optimize code