Added wrapper for mail() function
minor modifications and bugfixes