Implement retrieveMessages.
Implement tests for retrieveMessages