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

Change-Id: I7d3b6ca27d11a2ac5d1f1d26f586bc91e005ad85