Implementation of set() function.