Apply patches from Alberto Ruiz