refactor: move stability split logic into a separate function