Refactor and test solution output