Attempted fix of share state by moving things inside if condition