removes code duplication; fixes #12