Trouble properly using buffers for function