Restructure project and refactor code