serial number logic