changed a head:tail split to be pattern recognizion