corrected the code path structure and documented the code