Minor code cleanup and addition of comments