also not sure if it's causing any trouble but I think the select_for_update can be removed. I originally put it in to try and fix the race condition but that never really worked out as you know..