[TIMOB-14936][TIMOB-14937](3_1_X) Backports

Backport of PR #4607 and PR #4606

Fixes [TIMOB-14936](https://jira.appcelerator.org/browse/TIMOB-14936) and [TIMOB-14937](https://jira.appcelerator.org/browse/TIMOB-14937)