HTML emails, minor refactoring and lesser fixes