document this crappy algorithm