added state maintainance code