Fix various bugs with subs