Added many comments and shuffled things around