merged the changes from Gunnar's version