Added __getstate__ and __setstate__ to enable pickling