made prepare statement and moved code around