made a few changes to check buffer size