Merged with Gavins code
conflict resolution