sanitize function improved