Changes to the onValueChanged() function, bug fixes