Refactoring mqtt_listen into process and helper methods