I just tried your script and it works for smaller databases but fails on any of our large (and heavily fragmented) production databases with
Msg 220, Level 16, State 1, Line 1
Arithmetic overflow error for data type smallint, value = 65602.
The problem doesn't seem to be in the view itself. I will troubleshoot it when I can find time. It may work once I can bring the fragmentation issues under control, but that may be months or years from now.