Fix for issue 33 and 38

Issue 33 and 38 report the same defect. I added a test to show this issue and also added a fix.
Pleas let me know if the code style is not appropriate.