Fix fencepost

A late change to the epoch code changed the owner of the sequence named in the epoch. This is fixed in the first commit in the Pull Request. Subsequent commits tidy the code for readability and add further tests and validation of epoch input for safety.