Refactored some code in check_phrase func