         else
           console.log(@words)
 
-        for letter in path
-          $(".row#{letter.y}.col#{letter.x}").addClass("solved#{solvedNumber}")
+        # Highlight cells in path
+        for cell in path
+          cell.$cell.addClass("solved#{solvedNumber}")
         solvedNumber = (solvedNumber+1)%3
 
       else
         console.log("\"#{foundWord}\" is not a correct word")
 
-      @selected.removeClass('selected')
+      @selected.$cell.removeClass('selected')
       @selected = null
     else
-      @selected = $cell
-      $cell.addClass('selected')
+      @selected = clicked
+      clicked.$cell.addClass('selected')
 
 
   _fillGrid: (wordlist, attempts) ->

      for x in [0..@width-1]
        $cell = $('<div/>')
        $cell.addClass('ws-cell')
        $cell.text(@grid[y][x])
        $cell.data('position', [x, y])
        $cell.addClass("row#{y}")
        $cell.addClass("col#{x}")
        $cell.appendTo($row)
        $cell.click($.proxy(@_cellClicked, this, $cell, x, y))
    @$grid.appendTo($container)

    console.log(@words)


  _cellClicked: ($cell, x, y) ->
    if @selected?
      path = @reconstructWord(@selected.data('position'), $cell.data('position'))
      foundWord = ''
      if path?
        for letter in path
          foundWord += letter.letter

      if foundWord in @words
        console.log("\"#{foundWord}\" has been found")

        @_tryPutWord(word) if word not in @words

    # Fill in all unfilled slots with random letters
    cell.randomFill() for cell in row for row in @cells


  _tryPutWord: (word) ->
    # Choose a random start and end point
    [startX, startY] = randomStartingPoint(@width, @height)
    [dirX, dirY] = randomDirection()
    [endX, endY] = [startX+dirX*(word.length-1), startY+dirY*(word.length-1)]

    cells = @path([startX, startY], [endX, endY])

    # Return if word will not fit in grid
    return false unless cells?

    # Return if any cell is already filled
    for cell, i in cells
      return false unless cell.willFitLetter(word[i])

    # Set the new word
    for cell, i in cells
      cell.setLetter(word[i])
    @words.push(word)
    return true


  path: (start, end) ->
    [x, y] = start
    [endX, endY] = end

