Add comments and streamline code