Massive loc refactor