Added more comments, some code cleanup