fixed armies of bugs and added unittests for saving