Applying patches from Henning Thielemann