refactor and add notes.