fixing buffer bug, not completed