Modify readfunc to pass buffer