changed the way endbuf is referenced