Cleanup

I also manually brought in @PaintNinja 's PR. I decided to put it in a
util to not repeat the same lines of code everywhere. Thanks :).

Signed-off-by: Chris Sanders <zidane@outlook.com>