refactor prepare