get_project_filepath() converts candidate file paths to relative form twice, once in the first iterator, and then in vim.tbl_map() call while. It also iterates the same list twice for no apparent reason. Combine both scans into one and use dedicated vim.fn.isdirectory().