Fixed issues #45 and added a supporting unit test