More refactoring. This fixes #1