Current version of code from Dave and Jeroen