Some mods to Andrews Sobral's code