refactoring of existing code for keyword_resolution function