Added unit tests to fix #1.