Finished first version of Song algorithm