added code from Shan