move overlay into its own function