now working with downsampling as well