rewrote most of the dist module from lib601