Fix root directory in directory-wise metadata and beautify code