Copying across changes from jaffa library.