Add test for #160
Code tweaks