Refactor message listener to switch-case block, standardize message
format