Counts was taken from outside scope in function, properly replaced by x (the passed argument).