Finished body of the main loop and helper functions stubs.

Change-Id: Iabfd993cba5f788300b18b83d17b06c528359901