Fixes interactions with popen handles

Includes logging updates and other optimizations/improvements.

Change-Id: Icf704164292637b92da25d8c720a72a5ca7c6ba6
Closes-Bug: 1381195