reformat and refactor test code