Refactor of the set method