Moved AB-CD comparison code to the top of the file.