added email and reorganized code