refactor the messages controller