Refactor read_uri function

Change-Id: I7a7fbdfaeec7fc8fc0a22021d0640848a5f08e87