Optimized set and get state functions.