Applied Renato's Patch, with some modifications