cleanup code a bit

Some formatting, some logic
Why move this up?