Tweaking a few of the changes from @mrtiller