Changing "loc" to "aggfield" in the second line of the "aggregate"
function fixed all of my aggregate problems so its all working now!