Implemented saving and loading, cleaned up code.