Merge changes from @pma. Fixes #2