refactoring and code cleanup, closes #16