Fix various type and reference issues

Change-Id: Iced174d9f94faf80c5fa21e15fa6c81b6d8fa21c
Merge "Fix various type and reference issues"