Fix for #129

And also some overdue cleanup.