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)