Updated code to reuse prepared statement