some refactoring cleanup, closes #17 and #13