better error handling, reconnection and moved callbacks to publisher