improved and remove buffer