Reordered script body for readability