Some error handling in the database, restoring closed connections and always creating new prepared statements in stead of reusing old ones.