fix for issue #1121

I've added fix and tests