fix for issue #137 and added unit tests for #156