Add better error detection. Add support for optional trailing slash in path.