The basename function does not quote parameter

Leads to errors if the pathname contains spaces.

Also some minor WS fixes.