Modified the finalizeAssembly function