clarified lisibility

brought coherance and clarification in the syntax and factorised the
main function