Merged with Luiz modifications