Cleaned up IMAP code a bit