File Rewrite and form logic