Generalized function for setting value