Improve comments and streamline some code