Refactor into sendNativeEvent function