Several fixes [MJ-382]

- Add tests for expired messages
- Fix code retrieving messages
- Add comments