Adding comments and code cleanup