added null check on books