Updated with latest code amended by XEX