Tried a different way so as not to create the buffer everytime.