big cleaning and refactoring

Change-Id: Iea4dc2c983555cf7769aabce02be6e7d014ad5d2