these two if statements can be replaced with `$path = trim($path, '/')`