reverted to christoph's version with minor changes