Fixed code for finding stable regions over time