refactored code

closes #12