refactor some code
fix outsources mail code