Refactor message consuming logic