Resubmitting #2030 for @averagesecurityguy

I added a couple fixes. Should be ready to land.