Refactor code and directory structure