balancing brackets with the stack