refactor which places confine outside of setcode block

as per adrienthebo's request