Added sort flags and (untested) conversion of mem usage to kb.
Recoded if statements to one-liners.