Refactor sanitize functions