Modified and updated to be used with this latest code.