Re-use newPivotStatement function

Signed-off-by: Dries Vints <dries.vints@gmail.com>
Various fixes

Fixed typos, incorrect property and incorrect return types.

Signed-off-by: Dries Vints <dries.vints@gmail.com>
Merge pull request #1664 from driesvints/dv/various-fixes

Various fixes