reorganized code, added flags to ensure docs