Changes on appcontroller, add email functions and other global vars