Sort order consistent and starting from 0

The Admin UI sorts the elements from index 0 instead the middleware expects 1+ indexes. So, if you update the first item in the list, the lazy `if` statement changes `sortOrder` to the max + 1.
Adding a type check should fix this wrong behaviour and make the index 0 based across the board.