repatched battery management code