Rearranging the code structure to allow replacing state logic.

Change-Id: I6f83d0f77045ba189f02dd465bf70ffc2a239aa1
15 files changed