[TIMOB-13831] Code cleanup and potential bug fixes.