moved a few lines around for readability.