Added more comments, streamlined some code