public void write() {
        if (!valid()) {
            System.err.println("Not saving invalid map");
            return;
        }
        try {
            ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(filepath()));
            output.writeObject(this);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }