refractored var's & changed order of output