[WIP] Move code context creation

Refactoring this a bit to move the code context creation out.

WIP until I finalize it. Just wanted to show what my direction is while you're working in the same code base. ;)