unused code removed, all functions documented