Updated code - work in progress