clean up image code a bit