reordered script for clarity