Some corrections, and more use of prepared query