Fixed #228 and added a test for it.
Cleanup for #228.
Merge pull request #231 from trustmaster/master

Fixed #228