consolidate refactored code from flashcard1