fix for issue #144, added unit tests