cleanup trailing whitespace and stop the counter when it maxes out.