General fixes to logic