Pla 1539

Code cleanup and refactoring

DO NOT MERGE, wait for QA