improved imap connection management