Added automatic resizing on state change