Refactor backoff into State class, add (terrible) tests, some cleanup