Small refactoring

rearrange some bits, rename a variable or 2