Adding comments and minor code cleanup