last version before making some multithreading experiments :)