Simplify main module source code, and attempt to improve overall performance.