Add comments and improve performance of a comparison