changed the ordering of some stuff to make the script make more sense