Fix issue #60 and add regression tests