add comments, updates, remove closing tag

Fixed a couple bugs, added comments, removed closing PHP tags