improve helpers for removing invalid values