Script fixes and structural changes