Adding comments and minor rearranging