Added comments.  Fixed mean and median logic.