big refactoring

Change-Id: Ib1898c2e17e73d51f6eec45cc16f2085f37ab85b