add function to mark and swap buffers