Restruct the code of GetImages