Adding PHPDoc comments and other comments.
Also cleaned up code