take_matches.js refactoring