refactored the saving and loading, fixed some bugs.