EB-6963 & EB-6893. Added more comments, format changes and renamed few  variables and method names and some small changes done based on code review.