Improve resync handling code, resolving issue #56

- Force resync count to be an integer
- Tidy up a very confusing set of if tests (correct, but unreadable)