Cleaned up unneeded sort.
Using bytes counters to infer whether a file was used as input, output, or both. This is more reliable than the open mode. Might cause trouble with descriptors that are closed by forked childs.