Reorganized code and enabled it to be minimized by chunks.