bugfix for ties; improved performance