Added comments, logging and default value empty array  for null if related ids is deleted