Fixed save algorithm and also saved user state.