Refactor top result code