fixed some buffer problems