Refactor pivoting