     book = getBookAtIndex(index)
     newRating = parseInt(newRating, 10)
 
-    currentAverage = book[BOOK.RATING].value
-    nbrOfReviews = book[BOOK.REVIEWCOUNT].value
+    currentAverage = 0
+    nbrOfReviews = 0
+
+    if book[BOOK.RATING] and book[BOOK.REVIEWCOUNT]
+      currentAverage = book[BOOK.RATING].value
+      nbrOfReviews = book[BOOK.REVIEWCOUNT].value
 
     newTotalOfAllRatings = currentAverage * nbrOfReviews + newRating
 

#   hubot booklist lookup <index> - retrieves book information
#   hubot booklist - displays full booklist
#   hubot booklist edit <index> <title> - edit book at index with new title
#
# Author:
#   Thomas Gamble & Paul Gaffney


  robot.hear /booklist review book (\d{1,5}) stars (\d{1})/i, (res) ->
    index = res.match[1]
    reviewRating = parseInt(res.match[2], 10)

    if reviewRating > 5
      return emitString(res,"Ratings must be between 1 and 5")

    maxIndex = getBookList().length - 1
    if index > maxIndex
