Detect basename correctly