refactor and reformat