Improves sanitize funtion based on feedback from @rui314. Thank you!