Merge big chunk into branch

Did big refactoring