refactored to use stdin/stdout and added test
Merge pull request #1 from rm8t/master

refactored and added test