use download links instead of direct links. Make sure the correct security settings are used. refactoring of code