Refactoring and some preparations