Move code for finding imports into a distinct function