Add function to locate main binary and option to dump it.
Other cleanups and cosmetic fixes.