Added comments and code cleanup