Refactoring. Still working on upload.