Refactored JS for resource submission