Issue 3

Refactored previous pull request, added supporting test cases.