major code and documentation rework