Put storing state into a function