adding global error callback, presence heartbeat value validation, removing duplicate code