Working serial implementation