added email script and cleaned up code some
added email script, cleaned code