Fix pipe rotation code

Closes #1022