Major code refactor for upload form