Apply three patches from Assar Westerlund <assar@kth.se>: