patch from reddit.com/user/weshmashian