sequential version fully working