Fix for #391, second attempt :)
Attempt 3 at #391
Added testcase for #391
Merge pull request #392 from appedemic/master

Fix for #391, second attempt :)