Partly refactored code using models and constants to clean up interface with backend
Updated IMAP to use new models