small changes, if #states is not prime, it sets the charac to next prime