Minor cleanup and moving around code for clarity

Adding a couple of tests to cover some cleaned up lines.

Change-Id: I1a4a73694f16a35967c313625bc4260045500ab9
Merge "Minor cleanup and moving around code for clarity"