updated prepare function