Fix some remaining bugs before reuse elsewhere