Correct bug and add save function.