Major Cleanup: better modularization.