Implemented the embedding algorithm correctly