reorganized code into mode modules