Fixed #2

Added a test for the bug as well.