start amending copied stuff from pivot.js