Handling of data.frame was buggy because of double assignment.
count <<- as.matrix(count)
does not seem to change the local variable 'count'