Fixed save function