safer buffer creation