added dectection for end of scenes