Fixes, refactoring and inner reference to java.mail