Bug fixes for prepared statements