Rebased PR #55

This should be good to merge to master.