Better errors and state handling