Reordering functions.

Let the command implementation have the same order as they have in the
command definition callback.
Moved the info gathering code to common function. Closes #3.