fixed overlay function bug