this is the first version
I will use this as reference and convert it into multithreaded version