fixed the upload page -> now it works by itself.   Moved all functions into a separate file