added pickling, fixed bug with writing pops to file