integrate patches from Gerardo Curiel