Represent state ids as unsigned shorts

This fixes some signedness conversion warnings