Fix #149 and a couple other issues