More re-factoring to the new API and fixes on parameterized queries