Messed around with the prepared SQL statements, and cleaned up code elsewhere.