Fixes for #156 and some of #164.