You have this code duplicated, maybe you could make it 'global'?