refine sanitize function