patch with latest modifications from alejandro <=> initial submitted version