Improved the change algorithm