refactored code
resolves #7 to as much as I'd like it