refactoring js functions csv post