Fix race condition were second to last image was chosen insteaf of last one