code refactor, without downsampling