some more refactoring and a bit code changes