Finalized second implementation