Move load/save state to separate functions