complete reorganization of code