Updated code from Calum