fixed download function