Merge "Multiple bugfixes, small restructuring."
am: 26b614ddf6

Change-Id: I7a44bbfe9f43981031fc6cc84de08cef79d78e78