merge parts of #236 (by ShawnTuatara)