fix scale algorithm