Do -directory check before any work is done.
Fix some formatting.