added window parameter for end matching