added download() function, code formatting