Updated to also retrieve folder if present