Updated code copied from smaller