Pick up some logic together and simplify it, plus minor fixes