add locking mechanism when downloading images