Further tweaking of circular buffer, write function