add function to remove invalid characters