refactor by farthinker