Refactor complete. test4 and test5 pass 100%