fixed a few bugs with prepared statements and updating RelatedCount