This is the primary fix. I can clean it up and make a feature branch if you'd like.