cloned from https://github.com/lastlegion/hog