Add tests for state restriction and fix few issues they found