Polishing; added code of original algorithm for comparison