Refactored the script to take comments into account.