pivot function drafted, not yet working correctly
reworking pivot function
pivot function working