Refactor and add code to save embedding value