Modified Dr. Debray's bashscript