added term selection logic to result.rb