Correct failing tests and fix remaining bugs