Stolen shamelessly from craigemery to make it more pathogen-compatible