Fix for #80 (with tests)