fixes #1809 - actually works.  Needs refactoring