Move essential code to 'submitData'