Imap refactored.