finished refactor after seen the solution.