Improving qubit coherence using closed-loop feedback