refactoring preparation code