Implementation of rescaling function