Implemented sequential version.