Refactoring

WARNING!
First commit (fe3c90b6e23b899241884baed1827d29babcf439) revert commit from merge with Grandis/master (15acf013e5c682973856eab43a6e8b9fe31320df).
Reason: need to work with not refactored sources.