Added changes from ElementalX

added code from ElementalX.