Initial implementation of #30. Started changes for #29