Support for reactive sorting. Fixes #477
Checking more edge cases.