mostly docco, a few tweaks to make things controllable via env variables