improve comments, restructure some code, add options to fork