The original python script which was originally an awk script