refactoring and more contract checks