Make use of path methods and remove extension more securely