refactoring of emails parser