massive rewrite, drop the function call and simplify things
boom, script complete and full tidy data set