add fix for issue #49 and add tests