refactoring of jquery to transform form data to json