Fixed #24 and added unit test to prevent future regressions.