Add jasmine tests
Add additinal state checks to avoid errors