fixed image script, some cleanup