initial work for #50 and (hopefully) #51. Working branch including other fixes, will be MR'd separately.