Improve value setting and resetting logic