implement change algorithm