refactoring and pack of fixes