Fix infinite loop with multiple staff sizes
Fixed staff filter to be robust against long beams