Fixes both #16 and #35 (two birds, one stone!)