More refactor, way better scope handling