Restructured the whole source code