refactor function making overlays