Added buffering and multithreading