finish refactor of the code