refactor prepare() to reduce complexity