Issue 1269

Fixes #1269. Includes a refactoring commit.