reformat and add unit tests