refactor and fix message display