Rewrote handling of uploaded files