updated code from lbnl