fixed error in upload controller, moved some code around