Added email queue and refactoring