Sorted the output. This is an additional version. DO NOT USE.