fix to handle >10 states and prettify expressions