Rearrange tests & before blocks, minor refactoring