Restructured code, listening to 'input' event to catch pastes by right-click->paste and on mobile devices