Debugged bash count function and added csum for automatic summing.