Assorted fixes to logic