Cherry pick @sharpred's changes to close #10 and #11