reverted back to original code without multithreading