Added retrying function if the image url responses 404 (other than 200).

Some big refactoring
Added some log code
Merge branch 'test'