Hi there,
Sorry for the inconvenience.. seems like I removed the statement to reset visibility for objects and replaced it with remerge only...
On top of function getAllFields just add this snippet code :
if (rootObject.isPropertySpecified("presence") && rootObject.presence == "visible") {
rootObject.presence = "hidden";
}