fixes distance calculation, moves mails to templates