added tests and shaved off a couple more lines
Merge pull request #2 from xrotwang/refactoring

added tests and shaved off a couple more lines