Updated code to take comments into account.