added a downscale algorithm