Refactored and added support for limiting the number of downloads

Signed-off-by: Dave Bush <davebush@gmail.com>