All selects changed to prepared statements and two bugs corrected