Fix a few build errors related to required type conversions and handling of references. Fixes #4440 Fixes #4441