This work is based on https://github.com/yonik/noggit