closes #12, manually including changes from it