improve source buffer locating function