Code refactoring
Added mail function support