updated serial version to match multithreaded