lots of clean up of mail sending script