Updated db calls to fix bug where image number will have already advanced before recording a skip/flag