final refactor of whole project