Some refactoring changes for #29