working version. single core. simple algo