Better algorithm for image grabber