Made the handling of paths more robust