Modded to incorporate upstream changes