This is taken from https://github.com/tj/n/