added patches by Reinier.