initial code for threading and buffer