improved top_word() function