changed the order of parameters and some refactoring for file download