Refactored and reorganized

Change-Id: I3cf2ea3e84367661c7e6e36adecddf9243b70a3d