Changed code ordering to make reading through easier.