Make more generic and more robust.