some code refactoring and preparing for merge to master