fully working script for looping images onto grid