Modified to submit userData on beforeunload