Improve resync handling code, resolving issue56

- Force resync count to be an integer
- Tidy up a very confusing set of if tests (correct, but unreadable)
Why the check on `self.resync_expected`? Is there any situation where that could be falsy, and if there is, why wouldn't we want to enter this block anyway?