started refactoring to work out why it fails silently