initial work for issue 399

not ready for merging