more comments. rearranged some functions