added functions for loading and saving state