clean_form function abridged