code cleanup, buffer fix