add defer to guard against unexpected panics