Added checks to make this script more informative.