Convert code to functions (to be able to load overlays from outside the domain)