Implemented  infrastructure for #23 and #6.